package Q1047

class Main {

}

fun main() {

}


class Solution {
    fun removeDuplicates(s: String): String {
        var res: StringBuilder = StringBuilder()

        var top = -1
        for (i in s.indices) {
            val c = s[i]
            if (top >= 0 && res[top] == c) {
                res.deleteCharAt(top)
                top--
            } else {
                res.append(c)
                top++
            }
        }
        return res.toString()
    }
}

